package log.controller;

import lombok.RequiredArgsConstructor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;

import java.util.List;
@RequiredArgsConstructor
public class ControllerLogListener extends AbstractControllerLogListener implements InitializingBean {

    private final List<ControllerLogger> listeners;

    @Override
    public void afterPropertiesSet() throws Exception {
        if (listeners != null && listeners.size() > 0) {
            register();
        }
    }

    @Override
    protected void log(Invocation invocation) {
        for (ControllerLogger listener : listeners) {
            try {
                listener.log(invocation);
            } catch (Exception e) {
                LOGGER.warn("",e);
            }
        }
    }
}
